package com.gxa.controller.shezhicontroller;

import com.gxa.common.R;
import com.gxa.pojo.GongYingShang;
import com.gxa.service.shezhiservice.GongYingShangService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author weishen
 */
@RestController
@RequestMapping("/GongYingShang")
@Api(value = "供应商管理" , tags = "供应商数据接口API")
@RequiresPermissions("供应商管理")
public class GongYingShangController {

    @Autowired
    public GongYingShangService gongYingShangService;

    @Autowired(required = false)
    public R r;
    @GetMapping("/selectAllGongYingShangForPage")
    @ApiOperation(value = "查询所有供应商信息接口",notes = "提供页码和每页显示数",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示数",required = true,dataType = "int",paramType = "query"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectAllGongYingShangForPage(@RequestParam int page,@RequestParam int size)
    {
//        r.setCode(200);
//        r.setMsg("查询成功");
//        List<GongYingShang> list = new ArrayList<>();
//        GongYingShang gongYingShang = new GongYingShang();
//        gongYingShang.setGongYingShangNumber("002");
//        gongYingShang.setGongYingShangMingCheng("五粮液");
//        gongYingShang.setPhone("18990009980");
//        gongYingShang.setLianXiRen("胡歌");
//        gongYingShang.setQiChuMoney(BigDecimal.valueOf(1000));
//        gongYingShang.setQq("123456");
//        list.add(gongYingShang);
//        r.setData(list);
//        return r;
        return gongYingShangService.selectAllGongYingShangForPage(page,size);
    }

    @GetMapping("/selectAllGongYingShangType")
    @ApiOperation(value = "查询所有供应商类别接口",notes = "提供页码和每页显示数",httpMethod = "get",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectAllGongYingShangType()
    {
       return gongYingShangService.selectAllGongYingShangType();
    }

    @GetMapping("/selectGongYingShangByTypeOrBianHaoOrLianXiRenOrMingChenOrPhone")
    @ApiOperation(value = "根据供应商类别、供应商编号、名称、联系人、电话查询",notes="提供供应商信息",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="page",value="当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name="size",value="每页显示记录数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name="gongYingShangType",value = "供应商类别",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="gongYingShangBianHao",value="供应商编号",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="lianXiRen",value = "联系人",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="phone",value="手机",dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectGongYingShangByTypeOrBianHaoOrLianXiRenOrMingChenOrPhone(@RequestParam int page,@RequestParam int size,String GongYingShangType,String GongYingShangBianHao,String GongYingShangMingCheng,String lianXiRen,String phone)
    {
//        r.setCode(200);
//        r.setMsg("查询成功");
//        List<GongYingShang> list = new ArrayList<>();
//        GongYingShang gongYingShang =new GongYingShang();
//        gongYingShang.setGongYingShangNumber("002");
//        gongYingShang.setGongYingShangMingCheng("五粮液");
//        gongYingShang.setPhone("18990009980");
//        gongYingShang.setLianXiRen("胡歌");
//        gongYingShang.setQiChuMoney(BigDecimal.valueOf(10000));
//        gongYingShang.setQq("123456");
//        gongYingShang.setZhuangTai(1);
//        list.add(gongYingShang);
//        r.setData(list);
//        return r;
        return gongYingShangService.selectGongYingShangByTypeOrBianHaoOrLianXiRenOrMingChenOrPhone
                (page,size,GongYingShangType,GongYingShangBianHao,GongYingShangMingCheng,lianXiRen,phone);
    }

    @PostMapping("/deleteGongYingShangById")
    @ApiOperation(value = "删除供应商接口",notes = "提供供应商id",httpMethod = "get",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteGongYingShangById(@RequestParam ArrayList<Integer> id)
    {
//        r.setCode(200);
//        r.setMsg("删除成功");
//        return r;
        return gongYingShangService.deleteGongYingShangById(id);
    }
    @PostMapping("/insertGongYingShang")
    @ApiOperation(value="新增供应商接口",notes="提供供应商信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insertGongYingShang(@RequestBody GongYingShang gongYingShang)
    {
//        r.setCode(200);
//        r.setMsg("插入成功");
//        return r;
        return gongYingShangService.insertGongYingShang(gongYingShang);
    }
    @PostMapping("/updateGongYingShangById")
    @ApiOperation(value="修改供应商信息接口",notes = "提供供应商信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateGongYingShangById(@RequestBody GongYingShang gongYingShang)
    {

//        r.setCode(200);
//        r.setMsg("修改成功！");
//        return r;
        return gongYingShangService.updateGongYingShangById(gongYingShang);
    }

}
